<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        // 方法1：2-n 
        function isPrime(n){
            if(n <= 1) return false;
            if(n === 2 ) return true;
            for(let i=2;i<n;i++){
                if(n%i===0){
                    return false;
                }
            } 
            return true
        }
        const result = [];
        for(let j = 1;j<=50;j++){
            if(isPrime(j)){
                result.push(j);
            }
        }
        console.log(result);
    </script>
</body>
</html>